﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class News : System.Web.UI.UserControl
{
    public string categoryId
    {
        set { Session["currCatId"] = value; }
        get
        {
            if (Session["currCatId"] == null)
            {
                Session["currCatId"] = "-1";
                return "-1";
            }
            return Session["currCatId"].ToString();
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            categoryId = Request.QueryString["nhomId"];
            bindGridPaging(categoryId, "-1");
            //bindOther("5", "7", categoryId);
        }
    }
    public string FormatImage(string imgPath)
    {
        if (!string.IsNullOrEmpty(imgPath))
        {
            return imgPath;
        }
        return string.Empty;
    }
    public string FormatLink(string id)
    {
        return "NewsDetail.aspx?id=" + id;
    }

    public string FormatVisibleImage(string imgPath)
    {
        if (string.IsNullOrEmpty(FormatImage(imgPath)))
        {
            return "display:none;";
        }
        return "";
    }
    protected void pager_Command(object sender, CommandEventArgs e)
    {
        int currnetPageIndx = Convert.ToInt32(e.CommandArgument);
        pager1.CurrentIndex = currnetPageIndx;
        bindGridPaging(categoryId, "-1");
    }
    public void bindGridPaging(string nhomId, string iActive)
    {
        TinTucDAO tintuc = new TinTucDAO();
        PagingOpbject obj =tintuc.news_GetByNhomId_Paging(categoryId, iActive, pager1.PageSize, pager1.CurrentIndex);
        rptNews.DataSource = obj.tableReturn;
        rptNews.DataBind();
        pager1.ItemCount = obj.totalRecords;
        //pager1.ItemCount = 10000;
    }
    //public void bindOther(string num,string numToSkip,string nhomId)
    //{
    //    TinTucDAO tintuc = new TinTucDAO();
    //    DataTable obj = tintuc.News_GetOtherByCategory(num,numToSkip, nhomId);// iActive, pager1.PageSize, pager1.CurrentIndex);
    //    rptTinBaiDaDang.DataSource = obj;
    //    rptTinBaiDaDang.DataBind();
    //}
   
}
